package com.zxl.live.tools.alert;

import android.content.Context;
import android.os.Build;

import com.zxl.live.tools.tools.MachineUtils;


/**
 * 功能： 悬浮窗相关工具类
 * 作者： caijun
 * 时间： 2017/3/1  10 : 38
 */
public class AlertPermissionUtils {

    public static boolean canAlert(Context context) {
        AlertState state;
        if (Build.VERSION.SDK_INT >= 23) {
            state = new HigherAlertState();
        } else if (Build.VERSION.SDK_INT >= 19) {
            state = new LowerAlertState();
        } else {
            return true;
        }
        return state.canAlert(context);
    }

    public static void gotoAlertManager(Context context) {
        GotoAlertManager manager = null;
        if (Build.VERSION.SDK_INT >= 23) {
            manager = new MGotoAlertSet();
        }
        if (null == manager || !((MGotoAlertSet) manager).canAction(context)) {
            if (MachineUtils.isMiui()) {
                manager = new MiuiGotoAlertSet();
            } else if (MachineUtils.isMeizu()) {
                manager = new MeizuGotoAlertSet();
            } else if (MachineUtils.isHuawei()) {
                manager = new HuaweiGotoAlertSet();
            }
        }

        if (null != manager) {
            manager.gotoAlert(context);
        }
    }

    /**
     * 获取是否有悬浮窗权限的接口
     */
    public interface AlertState {
        boolean canAlert(Context context);
    }

    /**
     * 跳转到悬浮窗管理界面的接口
     */
    public interface GotoAlertManager {
        void gotoAlert(Context context);
    }
}
